<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>方案申请页面</title>
    <link rel="stylesheet" href="../../res/layui/css/layui.css" media="all">
    <script src="../../res/js/jquery-3.1.1.min.js" type="text/javascript" charset="utf-8"></script>
    <script src="../../res/layui/layui.js"></script>
    <script src="../../res/js/Tools.js"></script>
</head>
<body>
<div id="container">
<form class="layui-form" action="" id="Leader">
    <input type="text" style="display:none" name="schemeId" id="schemeId"/>
    <input type="text" style="display:none" name="seId" id="seId"/>
    <div class="layui-form-item"></div>
    <div class="layui-form-item">
        <label class="layui-form-label">方案名称</label>
        <div class="layui-input-block">
            <input class="layui-input" type="text" readonly unselectable="on" name="saName"  id="saName" required
                   lay-verify="required" placeholder="方案名称" autocomplete="off"/>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">申请理由</label>
        <div class="layui-input-block">
            <input class="layui-input" type="text" name="applyForExp" id="applyForExp" required
                   lay-verify="required" placeholder="申请理由" autocomplete="off"/>
        </div>
    </div>
    <div class="layui-form-item">
        <div class="layui-input-block">
            <button class="layui-btn site-demo-active" lay-submit lay-filter="formDemo" >立即提交</button>
        </div>
    </div>
</form>
</div>
<style>
    body { font-family:Verdana; margin:0 auto;}
    #container {margin: 0 auto; width:600px;}
</style>
<script>
    layui.use(['form', 'layedit', 'laydate'], function() {
        var form = layui.form
            , layer = layui.layer
            , layedit = layui.layedit
            , laydate = layui.laydate;

        /**
         * 新增和修改
         */
        var form = null ;
        layui.use('form', function(){
            form = layui.form;
            //监听提交
            form.on('submit(formDemo)', function(data){
                // 单击之后提交按钮不可选,防止重复提交
                var DISABLED = 'layui-btn-disabled';
                // 增加样式
                $('.site-demo-active').addClass(DISABLED);
                // 增加属性
                $('.site-demo-active').attr('disabled', 'disabled');
                var rolesId = $('#schemeId').val();
                data.field.schemeId=rolesId;
                var formData = new FormData(document.getElementById("Leader"));
                var url = "../../AtsSchemeFsController/addAndUpdateExpert";
                $.ajax({
                    url:url,
                    type:"post",
                    data:formData,
                    processData:false,
                    contentType:false,
                    dataType:"json",
                    success:function(obj){
                        layer.msg(obj.msg, {
                            icon: 1,
                            time: 1000 //1秒关闭（如果不配置，默认是3秒）
                        }, function(){
                            //关闭当前层
                            //当你在iframe页面关闭自身时
                            var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
                            parent.layer.close(index); //再执行关闭
                            //刷新父页面
                            parent.location.reload();
                        });
                    },
                    error:function(e){
                        layer.msg("操作错误!");
                    }
                });
                return false;
            });
            findlx();
        });
        /**
         * 修改显示
         */
        function findlx(){
            var id = getQueryString("id");
            $("#schemeId").val(id);
            $.ajax({
                url: "../../AtsSchemeFsController/selectByPrimaryKey",
                type: "post",
                data:{schemeId:id},
                dataType:"json",
                success:function(obj){
                    $("#saName").val(obj.schemeName);
                }, error: function (e) {
                    alert('失败了');
                }
            });
            if(id){
                var url = "../../AtsSchemeFsController/selectBySchemeIdExpert";
                var data = {schemeId:id};
                //jquery的ajax方法,查询类型的方法
                $.get(url,data,function(obj){
                    //从后台传过来的数据obj$("[value='11']").prop("checked",true);
                    $("#applyForExp").val(obj.applyForExp);
                    $("#seId").val(obj.seId);
                    $("#remark").val(obj.remark);
                    //重新渲染
                    form.render();
                },"json");
            }

        }
    });
</script>
</body>
</html>
